define("proinfo",["jquery","jquery.cookie"],function(){
    return  {
        //商品信息
        proinfo:JSON.parse(sessionStorage.getItem("proinfo")||"{}"),
        //加载商品信息
        load:function(){
            var self=this
            $(".pro").html("")
            if(sessionStorage.getItem("proinfo")){
                $(`<title>${self.proinfo.name1+self.proinfo.name2}</title>`).appendTo($("head"))
                $(` <div class="left">
        <i>
            <b>${self.proinfo.zk}</b>
        </i>
            <div class="smallbox">
                <div class="smallimg"><img src="images/proinfo-middle${self.proinfo.imgindex}-1.jpg" alt=""><div id="smallmove"></div></div>

            </div>
            <div class="list-warp">
                <a href="javascript:;" class="leftbtn"><img src="images/proinfobtn.png" alt=""></a>
                <div class="list">

                    <ul>
                        <li class="active"><img src="images/proinfo${self.proinfo.imgindex}-1.jpg" alt=""></li>
                        <li><img src="images/proinfo${self.proinfo.imgindex}-2.jpg" alt=""></li>
                        <li><img src="images/proinfo${self.proinfo.imgindex}-3.jpg" alt=""></li>
                        <li><img src="images/proinfo${self.proinfo.imgindex}-4.jpg" alt=""></li>
                        <li><img src="images/proinfo${self.proinfo.imgindex}-5.jpg" alt=""></li>
                    </ul>

                </div>
                <a href="javascript:;" class="rightbtn"><img src="images/proinfobtn.png" alt=""></a>
            </div>

        </div>
        <div class="right">
            <div class="righttitle">

                专门针对脆弱的眼周肌肤而调配，升级版结合 Ceramide Liquid Complex (CLX)，帮助对抗细纹、鱼尾纹、松弛、浮肿、眼圈等岁月痕迹，回复年轻紧致明眸！
            </div>
            <div class="rightbody">
                <div class="bodytitle">
                    <i>香港特快直送</i><i>零扣关</i><i>包税</i>
                    <a href="javascript:;">${self.proinfo.name1}</a>
                </div>
                <div class="bodytitles">

                    <span class="cnames">${self.proinfo.name2}</span>

                    <span>(<span class="does">${self.proinfo.does}</span>)</span>


                </div>

                <div class="detailword">
                    <a href="javascript:;">去眼袋</a>
                    <a href="javascript:;">去浮肿</a>
                    <a href="javascript:;">去细纹</a>
                    <a href="javascript:;">抗皱/去皱</a>
                    <a href="javascript:;">保湿</a>
                </div>

                <div class="rulewarp">
                    <ul>
                        <li>
                            <div class="one">配送</div>
                            <div class="two">香港发货，香港直送时间为3-10个工作天</div>
                        </li>
                        <li>
                            <div class="one">运费</div>
                            <div class="two pro-rule">
                                <span>满￥288免运费</span>
                            </div>
                        </li>
                        <li>
                            <div class="one">税费</div>
                            <div class="two">
                                <span style="color:#EC3E7C;">本商品包税，无需再额外缴纳。</span>
                                如有疑问，请联系客服咨询。

                            </div>
                        </li>
                        <li>
                            <div class="one">服务</div>
                            <div class="two server">
                                <span>30日退换保证</span>
                                <span>正品保障</span>
                                <span>价格承诺</span>
                            </div>
                        </li>
                    </ul>
                </div>

                <div class="product-information">
                    <div class="buy">
                        <div class="product-action">
                            <ul>
                                <li>
                                    <span>数量:</span>
                                    <span>
                                        <a href="javascript:void(0);" class="btn-decrease">-</a>
                                        <input type="text" value="1" class="pronum">
                                        <a href="javascript:void(0);" class="btn-increase">+</a>
                                    </span>
                                </li>
                                <div>

                                    特卖价
                                    <span class="cur">￥<span>${self.proinfo.curprice}</span></span>
                                    <span class="old">市场价 ${self.proinfo.oldprice}</span>
                                </div>
                                <li style="margin:40px auto">
                                    <a href="javascript:void(0);">立即抢购</a>
                                    <a href="javascript:void(0);">加入购物车</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bigbox">
            <img src="images/pro-big${self.proinfo.imgindex}-1.jpg" alt="">
        </div>`).appendTo($(".pro"))
            }else{
                window.location="pro.html"

            }

        },
        //放大镜
        Magnifier:function () {
            var self=this
            $(".smallimg").mouseenter(function () {
                $("#smallmove").show()
                $(".bigbox").show()
                $(document).mousemove(function (evt) {
                    var e = evt;
                    var disx = e.pageX-parseInt($(".pro").css("marginLeft"))-parseInt($(".smallimg").css("marginLeft"))-parseInt($(".smallbox").css("marginLeft"))-100
                    var disy = e.pageY-parseInt($(".smallbox").css("marginTop"))-163-108-11-75
                    if(disx<0){
                        disx=0
                    }
                    if(disx>100){
                        disx=100
                    }
                    if(disy<0){
                        disy=0
                    }
                    if(disy>150){
                        disy=150
                    }
                    $("#smallmove").css({
                        left: disx,
                        top: disy
                    })
                    $(".bigbox img").css({
                        left:-2*disx,
                        top:-2*disy
                    })
                })
            })
            $(".smallimg").mouseleave(function () {
                $("#smallmove").hide()
                $(".bigbox").hide()
                document.onmousemove=null
            })

            $(".leftbtn").click(function (){
                    $(".list ul").animate({"left":0},250)

            })
            $(".rightbtn").click(function () {
                $(".list ul").animate({"left":-120},250)

            })

            $(".list ul li").mouseenter(function () {
                $(this).addClass("active").siblings().removeClass("active")
                $(".smallimg img").attr("src",`images/proinfo-middle${self.proinfo.imgindex}-${$(this).index()+1}.jpg`)
                $(".bigbox img").attr("src",`images/pro-big${self.proinfo.imgindex}-${$(this).index()+1}.jpg`)
            })
        },
        //购买商品
        shopping:function () {
            var self=this
            //减号键
            $(".btn-decrease").click(function () {
                if ($(".product-action input").val()>=2){
                    $(".product-action input").val($(".product-action input").val()-1)
                }
            })
            //加号键
            $(".btn-increase").click(function () {
                if ($(".product-action input").val()<=20){
                    $(".product-action input").val(parseInt($(".product-action input").val())+1)
                }
            })
            //立即购买
            $(".product-action li").eq(1).children("a").eq(0).click(function () {
                var mark=parseInt($(".product-action input").val()*$(".cur span").text()/100)
                if(sessionStorage.getItem("oluser")){
                    $.ajax({
                        url:"php/addmark.php",
                        type:"post",
                        data:{
                        mark:mark,
                            uid:JSON.parse(sessionStorage.getItem("oluser")).u_id
                    }
                    }).then(function (res) {
                        alert("购买成功")
                        require(["base"],function (run) {
                            run.isonline()
                        })
                    })
                }else{
                    alert("请先登录")
                }
            })
            //加入购物车
            $(".product-action li").eq(1).children("a").eq(1).click(function () {
                if(sessionStorage.getItem("oluser")){
                    var cartobj={
                        c_path:`images/proinfo${self.proinfo.imgindex}-1.jpg`,
                        c_name:($(".bodytitle a").text() + $(".cnames").text()).trim(),
                        c_does:$(".does").text(),
                        c_price:$(".cur span").text(),
                        c_num:parseInt($(".product-action input").val()) ,
                        u_id:JSON.parse(sessionStorage.getItem("oluser")).u_id
                    }
                    $.ajax({
                        url:"php/addcart.php",
                        type:"post",
                        data:cartobj
                    }).then(function (res) {
                         if(confirm("添加成功!是否进入购物车")){
                             window.location="cart.html"
                         }
                    })
                }else{
                    var cartobj={
                        c_path:`images/proinfo${self.proinfo.imgindex}-1.jpg`,
                        c_name:($(".bodytitle a").text() + $(".cnames").text()).trim(),
                        c_does:$(".does").text(),
                        c_price:$(".cur span").text(),
                        c_num:parseInt($(".product-action input").val()),
                    }
                    var usercart=JSON.parse(sessionStorage.getItem("cart")||"[]")
                    var cartflag=true
                    for(var i=0;i<usercart.length;i++){

                        if(usercart[i].c_name==cartobj.c_name){
                            usercart[i].c_num+=cartobj.c_num
                            cartflag=false
                            break
                        }
                    }
                    if(cartflag){
                        usercart.push(cartobj)
                    }
                    sessionStorage.setItem("cart",JSON.stringify(usercart))
                    if(confirm("添加成功!是否进入购物车")){
                        window.location="cart.html"
                    }
                }
            })
        }
    }
})